//回复留言
function reply_msg(form){
	var name = (form.uname.value).replace(/(^\s+)|(\s+$)/g, '');
	var msg = ($(".nicEdit-main").html()).replace(/(<br>)|(&nbsp;)|[ ]/g, ''); 
	var validate = (form.validate.value).replace(/(^\s+)|(\s+$)/g, ''); 
	if(!name){
		$('.form-uname').html('请填写您的名字！');
		return false;
	}
	$('.form-uname').html('');
	if(!msg){
		alert('请填写您要回复的内容！');
		return false;
	}
	if(!validate){
		$('.form-validate').html('验证码不能为空！');
		return false;
	}
	if(validate.length != 4){
		$('.form-validate').html('验证码长度必须为4位！');
		return false;
	}
	$('.form-validate').html('');
	var query = {name : name, msg : msg, validate : validate};
	getMsg($('.table-comment'), form, query);
}

//获取并显示留言
function getMsg(table, form, query){
	
	var url = $(form).attr('url');
	$.post(url, query, function(data){
		if(data.content != 'ok'){
			alert(data.content); return false;
		}
		
		//追加留言
		var html = '<tr><td width="7%">&nbsp;</td><td width="7%"><i class="icon icon-talkbox">0</i></td>';
		var T = new Date();
		var y = T.getFullYear();
		var m = T.getMonth();
		var d = T.getDate();
		var h = T.getHours();
		var m = T.getMinutes();
		var time = y+'-'+m+'-'+d+'&nbsp;'+h+':'+m;
		html += '<td class="td-content" width="60%">'+time+'　'+$(".nicEdit-main").html()+'</td>'
		html += '<td><ul><li class="comment-user"><i class="icon icon-user"></i>'+form.uname.value+'</li></ul></td></tr>';
		$('.table-comment').prepend(html);
		//清空表单数据
		form.validate.value = ''; $(".nicEdit-main").html('');
		//刷新验证码
		changeCode('vdimgck');
	}, 'json');  
}